package com.a3dweijing.wetouch2.Common.listview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by Administrator on 2018/3/23.
 * listview公用
 */

public abstract class CommonListviewAdapter<T> extends BaseAdapter
{
    public Context context;

    public List<T> list;
    
    private int layoutId;
    

    public CommonListviewAdapter(Context context, List<T> list, int layoutId)
    {
        this.context = context;
        this.list = list;
        this.layoutId = layoutId;
    }
    
    @Override
    public int getCount()
    {
        
        return list.size();
    }
    
    @Override
    public T getItem(int i)
    {
        return list.get(i);
    }
    
    @Override
    public long getItemId(int i)
    {
        return i;
    }
    
    @Override
    public View getView(int i, View view, ViewGroup viewGroup)
    {
        ViewHolderListview holder;
        if (view == null)
        {
            view = LayoutInflater.from(context).inflate(layoutId, viewGroup, false);
            holder = new ViewHolderListview(context, view, viewGroup, 0);
            view.setTag(holder);
        }
        else
            holder = (ViewHolderListview)view.getTag();
        convert(holder, list.get(i),i);
        
        return view;
    }
    
    public abstract void convert(ViewHolderListview holder, T t,int position);
}
